<?php

declare(strict_types=1);

namespace App\Model\Users;



use App\Model\Model;
use App\Utils\HelperUtils;

/**
 * @property int $id 
 * @property int $uid 用户 uid
 * @property int $card_id 会员卡模板 id
 * @property string $card_no 会员卡号
 * @property string $card_cids 会员卡关联类目 id
 * @property int $amount 卡金额，单位分
 * @property int $card_type 会员卡类型，1：用户领取，2：手动录入
 * @property int $use_type 消费类型， 1：一次性入账，2：消费入账
 * @property string $card_discount 卡折扣
 * @property string $card_color 会员卡颜色
 * @property string $card_name 会员卡名称
 * @property string $card_desc 会员卡描叙
 * @property string $user_name 持卡人姓名
 * @property string $company_name 发卡公司名称
 * @property int $to_uid 发卡用户 uid
 * @property int $status 卡状态，1：正常，2：锁定，3：注销
 * @property \Carbon\Carbon $created_at 录入时间
 * @property \Carbon\Carbon $updated_at 更新时间
 */
class UsersCardsInfo extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'users_cards_info';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'uid', 'card_id', 'card_no', 'card_type', 'use_type', 'card_cids', 'amount', 'card_discount', 'to_uid', 'card_color', 'card_name', 'card_desc', 'company_name', 'user_name', 'status', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'card_id' => 'integer', 'card_type' => 'integer', 'use_type ' => 'integer', 'amount' => 'integer', 'to_uid' => 'integer', 'status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];


    public static function getCardNo()
    {
        while (true)
        {
            $orderSn = HelperUtils::generateMemberCardEnhanced();
            $checkIsset = UsersCardsInfo::query()->where('card_no','=',$orderSn)->first();
            if(!$checkIsset)
            {
                return $orderSn;
            }
        }
    }

}
